package com.cebbank.group.demoweb.controller;

import com.cebbank.group.demoweb.bean.MyBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
/*
用来测试spring-validation
用来测试ribbonclient，请结合http-client-demo
 */
@RestController
@RequestMapping("/format")
public class DateTimeFormatController {

    @Value("${server.port}")
    private String port;
    //这里返回port，通过改变port来启动多份服务，用来测试ribbon的负载能力,
    //客户端可看到不同的返回值得知自己访问的是哪个端口

    @RequestMapping("/date")
    @ResponseBody
    public MyBean formatDate(String param1,Long param2){
        MyBean myBean = new MyBean();
        myBean.setAge(100);
        myBean.setDate(new Date(System.currentTimeMillis()));
        myBean.setName(this.port);
        System.out.println("param1:"+param1);
        System.out.println("param2:"+param2);
        return myBean;
    }

    @RequestMapping(value = "/date2",method = RequestMethod.POST)
    @ResponseBody
    public MyBean formatDate2(@RequestBody MyBean myBean ){
        System.out.println(myBean);
        myBean.setAge(myBean.getAge() * 2);
        myBean.setDate(new Date(System.currentTimeMillis()));
        myBean.setName(port);
        return myBean;
    }
}
